package service

import (
	"file_sys_server/model"
	"file_sys_server/serializer"
)

type ChannelSpecRegionService struct {
	Left1     uint   `json:"left1"`
	Right1    uint   `json:"right1"`
	Top1      uint   `json:"top1"`
	Bottom1   uint   `json:"bottom1"`
	BgFactors string `json:"bgFactors"`
}

// 裸条校准数据的增删改查

func (service *ChannelSpecRegionService) AddRecord() serializer.Response {
	record := model.ChannelRegionSpecUnionBean{
		// ID:        1,
		Left1:     service.Left1,
		Right1:    service.Right1,
		Top1:      service.Top1,
		Bottom1:   service.Bottom1,
		BgFactors: service.BgFactors,
	}

	err := model.DB.Create(&record).Error

	if err != nil {
		return serializer.Response{
			Code: 10003,
			Msg:  err.Error(),
		}
	}

	return serializer.Response{
		Code: 10000,
		Msg:  "success",
	}
}

// 获取校准数据
func GetChannelSpecRecord() (*model.ChannelRegionSpecUnionBean, error) {
	var calibration *model.ChannelRegionSpecUnionBean
	err := model.DB.Last(&calibration).Error

	return calibration, err
}
